package com.hjq.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hjq.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from big_event.user where username = #{username}")
    User getByUserName(String username);

    @Insert("insert into big_event.user (username, password, create_time, update_time) " +
            "VALUES (#{username}, #{password}, #{createTime}, #{updateTime})")
    void register(User user);

    @Update("update big_event.user set nickname=#{nickname}, email=#{email}, update_time=#{updateTime} where id=#{id}")
    void update(User user);

    @Update("update big_event.user set user_pic=#{avatarUrl}, update_time=now() where id=#{id}")
    void updateAvatar(String avatarUrl, Integer id);

    @Update("update big_event.user set password=#{newPwd}, update_time=now() where username=#{username}")
    void updatePwd(String username, String newPwd);
}
